//
//  OriginalStatuesView.m
//  SinaWeibo
//
//  Created by Apple on 16/8/20.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "OriginalStatuesView.h"
#import "UserModel.h"
#import "StatuesModel.h"
#import "PhotoCell.h"
#import "MJPhoto.h"
#import "MJPhotoBrowser.h"

#define kMargin 10

@interface OriginalStatuesView ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet UILabel *sourceLabel;

@property (weak, nonatomic) IBOutlet UIImageView *VIPImageView;

@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
/**
 *  图片容器
 */
@property (weak, nonatomic) IBOutlet UICollectionView *photoCollectionView;
/**
 *  图片容器高度
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoCollectionViewHeight;
/**
 *  微博高度
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myWeiboViewHeight;


/***************************************************************************/
//1.点击图片时,转换后未放大的frame/

@property (assign, nonatomic) CGRect oldPictureFrame;

@property (weak, nonatomic) UIImageView *photoImageView;

@property (weak, nonatomic) UIButton *coverView;

@end

@implementation OriginalStatuesView

-(void)awakeFromNib{
    
    self.contentLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 20;
    
}


-(void)setStatueModel:(StatuesModel *)statueModel{
    
    [super setStatueModel:statueModel];
    
    
    UserModel *user = self.statueModel.user;
    
    self.nameLabel.text = user.name;
    
    //    设置内容
    self.contentLabel.text = self.statueModel.text;
    
    //    设置来源
    self.sourceLabel.text = self.statueModel.source;
    
    //    设置事件
    self.timeLabel.text = self.statueModel.created_at;
    
    //    设置头像
    NSURL *URL = [NSURL URLWithString:user.profile_image_url];
    
    [self.iconImageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    //设置VIP
    if ([user isVIP]) {
        
        self.VIPImageView.hidden = NO;
        
        NSString *imageName = [NSString stringWithFormat:@"common_icon_membership_level%d",user.mbrank.intValue];
        
        //设置VIP图片
        self.VIPImageView.image = [UIImage imageNamed:imageName];
        
        self.nameLabel.textColor = [UIColor orangeColor];
    }else{
        
        self.VIPImageView.hidden = YES;
        
        self.nameLabel.textColor = [UIColor blackColor];
        
    }
    
    
    //计算原创微博高度,设置文字后要从新计算一下contentLabel的高度 并且加上他的y值就能得到原创微博的高度
    
    //计算文字高度
    CGFloat contentLabelHeight = [self.contentLabel systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height ;
    
    //计算collectionView高度
    NSInteger count = self.statueModel.pic_urls.count;
    NSInteger maxCol = 3;
    NSInteger row = 0;
    CGFloat cellHeight = 110;
    
    if (count >0 ) {
        if (count % maxCol == 0) {
            row = count / maxCol;
        }else{
            row = count / maxCol + 1;
        }
        CGFloat photophotoCollectionViewHeight = row * (cellHeight + kMargin) ;
        
        self.photoCollectionViewHeight.constant = photophotoCollectionViewHeight;
    }else{
        
        self.photoCollectionViewHeight.constant = 0;
    }
    
    [self.photoCollectionView reloadData];
    
    self.myWeiboViewHeight.constant = self.contentLabel.frame.origin.y + contentLabelHeight + self.photoCollectionViewHeight.constant;
    
}




@end
